﻿using Microsoft.AspNetCore.Mvc;
using MyToDo.Api.Context.Entity;
using MyToDo.Api.Controllers.Dtos;
using MyToDo.Api.Service;
using MyToDo.Api.Service.Parameters;
using System.Threading.Tasks;

namespace MyToDo.Api.Controllers
{
    [ApiController]
    [Route("/api/[controller]/[action]")]
    public class MemoController : Controller
    {        
        private readonly IMemoService service;

        public MemoController(IMemoService service)
        {
            this.service = service;
        }
        [HttpGet]
        public async Task<ApiResponse> Get(int id) => await service.GetSingleAsync(id);
        [HttpGet]
        public async Task<ApiResponse> GetAll([FromQuery] QueryParameter query) => await service.GetAllAsync(query);
        [HttpPost]
        public async Task<ApiResponse> Add([FromBody] MemoDto model) => await service.AddAsync(model);
        [HttpPost]
        public async Task<ApiResponse> Update([FromBody] MemoDto model) => await service.UpdateAsync(model);
        [HttpDelete]
        public async Task<ApiResponse> Delete(int id) => await service.DeleteAsync(id);
    }
}
